%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% O-Ring Production Networks
%   Author: Demir, Fieler, Xu, Yang
%   Last updated: August 2022
%
% Purpose: Disecting Mechanisms
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
close all; diary off; clc; clear; 


%% Run each model

    % full model baseline counterfactual
    run('../3 baseline counterfactual/main_baseline_counterfactual.m')
    clearvars -except data eqm_cf1 ge_cf1 const eqm
    save('../../output/temp/fullmodel_counterfactual.mat');   

    % shut down nuv
    run('shutdown_nuv/main_shutdown_nuv_counterfactual.m')
    clearvars -except data eqm_cf1 ge_cf1 bartik model
    save('../../output/temp/shutdown_nuv_counterfactual.mat');   

    % shut down nuy
    run('shutdown_nuy/main_shutdown_nuy_counterfactual.m')
    clearvars -except data eqm_cf1 ge_cf1 bartik model
    save('../../output/temp/shutdown_nuy_counterfactual.mat');   

    % no complementarity
    run('nocomplem/main_nocomplem_counterfactual.m')
    clearvars -except data eqm_cf1 ge_cf1 bartik model
    save('../../output/temp/nocomplem_counterfactual.mat');   

    % homogenous network
    run('homogenous_network/main_homogenous_network.m')
    clearvars -except data eqm_cf1 ge_cf1 bartik model
    save('../../output/temp/homogenous_network_counterfactual.mat');   


%% Load results

    clearvars
    model1 = load('../../output/temp/fullmodel_counterfactual.mat');
    model2 = load('../../output/temp/shutdown_nuv_counterfactual.mat');
    model3 = load('../../output/temp/shutdown_nuy_counterfactual.mat');
    model4 = load('../../output/temp/nocomplem_counterfactual.mat');
    model5 = load('../../output/temp/homogenous_network_counterfactual.mat');

    delete('../../output/temp/fullmodel_counterfactual.mat')
    delete('../../output/temp/shutdown_nuv_counterfactual.mat')
    delete('../../output/temp/shutdown_nuy_counterfactual.mat')
    delete('../../output/temp/nocomplem_counterfactual.mat')
    delete('../../output/temp/homogenous_network_counterfactual.mat')


 %% Output tables and figures
diary off

    % create folder
    mkdir('../../output/tables') 

    % output table
    out_mechanisms_tables
    

